package edu.ctbu.insurance.util;

import edu.ctbu.insurance.vo.Result;
/* result构造工具类，用于快速构造Result对象 */
/* 用法：ResultUtils.success(数据对象如：List<xxx>) */
public class ResultUtils {
    public static Result success(Object data){//通过数据（data）快速构造 成功的Result对象
        Result result = new Result();
        ResultEnum resultEnum = ResultEnum.SUCCESS;
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setData(data);
        return result;
    }
    public static Result success(){//无参构造 成功的Result
        return success(null);
    }

    public static Result error(ResultEnum resultEnum){//通过枚举类，快速构造 错误的 Result对象
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }
    public static Result error(Object data,ResultEnum resultEnum){//通过枚举类和data，快速构造 错误的 Result对象
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        return result;
    }
}
